package offer;

public class offer18 {
}
class Solution18 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode fakeHead = new ListNode(-10000000);
        fakeHead.next = head ;
        ListNode pre = fakeHead;
        ListNode cur = head;
        boolean flag = false;
        while (cur!=null)
        {
            if(cur.val ==val)
            {
               flag = true;
               break;
            }
                pre = cur;
                cur = cur.next;


        }
        if(flag==true)
        {
            pre.next = cur.next;
        }

        return  fakeHead.next;
    }
}